package com.dragonfly.shutter.services;

import java.util.Date;
import java.util.List;

import com.dragonfly.shutter.DAOs.AlbumDAO;
import com.dragonfly.shutter.DAOs.BrowseLogDAO;
import com.dragonfly.shutter.beans.Album;
import com.dragonfly.shutter.beans.BrowseLog;

/**
 * 相册选择服务类
 * @author 黄挺
 *
 */
public class AlbumSelectService {
	private BrowseLogDAO browseLogDAO;
	private AlbumDAO albumDAO;
	
	/**
	 * 相册选择服务函数
	 * @param userID 用户ID
	 * @param requestURL 请求URL
	 * @return 用户的所有相册
	 */
	public List<Album> doService(Integer userID, String requestURL) {
		BrowseLog browseLog = new BrowseLog(userID, new Date(System.currentTimeMillis()), requestURL);
		
		return doDBOperate(userID, browseLog);
	}

	/**
	 * 相册选择数据库操作函数
	 * @param userID 用户ID
	 * @param browseLog 访问日志
	 * @return 用户所有相册
	 */
	private List<Album> doDBOperate(Integer userID, BrowseLog browseLog) {
		browseLogDAO.insertBrowseLog(browseLog);
		return albumDAO.selectAlbumByUserID(userID);
	}

	public void setBrowseLogDAO(BrowseLogDAO browseLogDAO) {
		this.browseLogDAO = browseLogDAO;
	}

	public void setAlbumDAO(AlbumDAO albumDAO) {
		this.albumDAO = albumDAO;
	}

}
